using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


/// <summary>
/// The PaymentTypeCodeTableManager class is responsible for managing BO.PaymentTypeCodeTable objects in the system.
/// </summary>
[DataObjectAttribute()]
public class PaymentTypeCodeTableManager
  {

#region "Public Methods"

/// <summary>
/// Gets a list with all PaymentTypeCodeTable objects in the database.
/// </summary>
/// <returns>A list with all PaymentTypeCodeTable from the database when the database contains any, or null otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, true)]
public static PaymentTypeCodeTableList GetList(){
return PaymentTypeCodeTableDB.GetList();
}

/// <summary>
/// Gets a single PaymentTypeCodeTable from the database without its data.
/// </summary>
/// <param name="paymentTypeCode">The PaymentTypeCode of the PaymentTypeCodeTable in the database.</param>
/// <returns>A PaymentTypeCodeTable object when the PaymentTypeCode exists in the database, or <see langword="null"/> otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static PaymentTypeCodeTable GetItem(Int16 paymentTypeCode)
{
return GetItem(paymentTypeCode, false);
}

/// <summary>
/// Gets a single PaymentTypeCodeTable from the database.
/// </summary>
/// <param name="paymentTypeCode">The PaymentTypeCode of the PaymentTypeCodeTable in the database.</param>
/// <param name="getPaymentTypeCodeTableRecords">Determines whether to load all associated PaymentTypeCodeTable records as well.</param>
/// <returns>
/// A PaymentTypeCodeTable object when the PaymentTypeCode exists in the database, or <see langword="null"/> otherwise.
/// </returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
public static PaymentTypeCodeTable GetItem(Int16 paymentTypeCode, bool getPaymentTypeCodeTableRecords)
{
PaymentTypeCodeTable myPaymentTypeCodeTable = PaymentTypeCodeTableDB.GetItem(paymentTypeCode);
if (myPaymentTypeCodeTable != null && getPaymentTypeCodeTableRecords){
myPaymentTypeCodeTable.teacherSalaryTables = TeacherSalaryTableDB.GetListByPaymentTypeCode(paymentTypeCode);
}
return myPaymentTypeCodeTable;
}

/// <summary>
/// Saves a PaymentTypeCodeTable in the database.
/// </summary>
/// <param name="myPaymentTypeCodeTable">The PaymentTypeCodeTable instance to save.</param>
/// <returns>The new PaymentTypeCode if the PaymentTypeCodeTable is new in the database or the existing PaymentTypeCode when an item was updated.</returns>
[DataObjectMethod(DataObjectMethodType.Update, true)]
public static Int16 Save(PaymentTypeCodeTable myPaymentTypeCodeTable)
{
using (TransactionScope myTransactionScope = new TransactionScope()){
    Int16 paymentTypeCodeTablePaymentTypeCode = PaymentTypeCodeTableDB.Save(myPaymentTypeCodeTable);
foreach (TeacherSalaryTable myTeacherSalaryTable in myPaymentTypeCodeTable.teacherSalaryTables){
myTeacherSalaryTable.PaymentTypeCode = paymentTypeCodeTablePaymentTypeCode;
TeacherSalaryTableDB.Save(myTeacherSalaryTable);
}

//  Assign the PaymentTypeCodeTable its new (or existing PaymentTypeCode).
myPaymentTypeCodeTable.PaymentTypeCode = paymentTypeCodeTablePaymentTypeCode;

myTransactionScope.Complete();

return paymentTypeCodeTablePaymentTypeCode;
}
}

/// <summary>
/// Deletes a PaymentTypeCodeTable from the database.
/// </summary>
/// <param name="myPaymentTypeCodeTable">The PaymentTypeCodeTable instance to delete.</param>
/// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
[DataObjectMethod(DataObjectMethodType.Delete, true)]
public static bool Delete(PaymentTypeCodeTable myPaymentTypeCodeTable){
return PaymentTypeCodeTableDB.Delete(myPaymentTypeCodeTable.PaymentTypeCode);
}

#endregion

}

